<template>
	<view class="container">
		<view>
			<uni-popup ref="popup" type="top" background-color="#fff">
				<view class="popup-content">
					<!-- <uni-forms ref="queryForm" :modelValue="queryParams">
						<uni-forms-item label="案件编号" label-width="85">
							<uni-easyinput v-model="queryParams.caseCode" placeholder="案件编号"></uni-easyinput>
						</uni-forms-item>
						<uni-forms-item label="上报时间" label-width="85">
							<uni-datetime-picker v-model="queryParams.reportTime" type="daterange"/>
						</uni-forms-item>
					</uni-forms>
					<view style="display: flex;">
						<button size="mini" class="common-btn other-btn" @click="handleRepeat">重置</button>
						<button size="mini" class="common-btn primary-btn" @click="handleQuery">查询</button>
					</view> -->
					<case-query-form @query="handleQuery"></case-query-form>
				</view>
			</uni-popup>
		</view>
		<view class="uni-list">
			<case-list-content :list-data="listData" :rows="rows">
				<template #btns="item">
					<button class="common-btn primary-btn"  size="mini" @click="handleDeal(item.data)">查看详情</button>
				</template>
			</case-list-content>
		</view>
		<uni-load-more :status="status" :icon-size="16" :content-text="contentText" />
	</view>
</template>

<script>
	import { getDicts } from "@/api/system/dict/data";
	import { dateUtils } from  '@/utils/util.js';
	import {selectQueryInfo} from "@/api/dums/caw/caseInfo";
	import caseListContent from "@/components/case-list-content/case-list-content"
	export default {
		components:{
			caseListContent
		},
		data(){
			return {
				queryParams:{
					caseCode:"",
					reportTime:[]
				},
				page:1,
				size:10,
				total:0,
				listData: [],
				reload: false,
				status: 'more',
				adpid: '',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				sourceOptions:[],
				rows:[{
					labelName:"案件编号",
					valueName:"caseCode"
				},{
					labelName:"当前环节",
					valueName:"linkName"
				},{
					labelName:"问题来源",
					valueName:"caseSource"
				},{
					labelName:"案件类型",
					valueName:"caseTypeName"
				},{
					labelName:"问题描述",
					valueName:"caseDesc"
				}]
			}
		},
		methods:{
			getList() {
				uni.showLoading({
					title:"加载中"
				})
				if (this.total && !this.reload) {
					//说明已有数据，目前处于上拉加载
					this.status = 'loading';
				}
				if(this.reload){
					uni.stopPullDownRefresh();
				}
				//默认只加载自己的案件
				this.queryParams.rptUserName = this.$store.state.user.userInfo.userName;
				this.queryParams.pageSize = this.size;
				this.queryParams.pageNum = this.page;
				selectQueryInfo(this.queryParams).then(res => {
					uni.hideLoading();
					if(res.code == 200){
						let list = res.rows;
						this.total = res.total;
						list.forEach(item => {
							if(item.rptChannelId){
								this.sourceOptions.forEach(opt => {
									if(opt.dictValue == item.rptChannelId){
										item.caseSource = opt.dictLabel;
									}
								})
							}
						})
						this.listData = this.reload ? list : this.listData.concat(list);
						this.reload = false;
						//判断是否最后一页
						if(this.size*this.page>=res.total){
							this.status="noMore"
						}
					}
				})
			},
			handleQuery(params){
				/* if(this.queryParams.reportTime &&　this.queryParams.reportTime.length>0){
					let params = {
						"rptTimeStart":this.queryParams.reportTime[0]+" 00:00:00",
						"rptTimeEnd":this.queryParams.reportTime[1]+" 23:59:59"
					}
					this.queryParams.params = params;
				} */
				this.queryParams = params;
				this.page = 1;
				this.reload = true;
				this.listData = [];
				this.getList();
				this.$refs.popup.close()
			},
			handleRepeat(){
				this.queryParams = {};
			},
			handleDeal(item){
				console.log(JSON.stringify(item));
				// console.log(item.caseId);
				uni.navigateTo({
					url:'../case-detail/case-detail?caseId='+item.caseId+'&linkForm='+item.linkForm
				})
			}
		},
		
		onLoad() {
			//问题来源
			getDicts("case_source").then(response => {
				this.sourceOptions = response.data;
			});
			
			this.page = 1;
			this.reload = true;
			this.listData = [];
			this.getList();
		},
		onNavigationBarButtonTap : function (e) {
			this.$refs.popup.open()
		},
		onPullDownRefresh(){
			this.page = 1;
			this.reload = true;
			this.listData = [];
			this.getList();
		},
		onReachBottom(){
			this.page++;
			if(this.listData.length < this.total){
				this.status = 'more';
			}else{
				this.status = 'noMore';
				return;
			}
			this.getList();
		}
	}
</script>

<style lang="scss">
	.popup-content {
		padding: 15px;
		height: 500px;
		background-color: #fff;
	}
	.nav-btn{
		margin-right: 15px;
	}
</style>